package com.andon.colbert.ffplayer;

import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class FFPlayer implements SurfaceHolder.Callback {

    static {
        System.loadLibrary("ffplayer");
    }

    private SurfaceView videoView;

    public void setSurfaceView(SurfaceView surfaceView) {
        SurfaceHolder holder = surfaceView.getHolder();
        holder.addCallback(this);
        display(holder.getSurface());
        videoView = surfaceView;
    }

    // 播放视频
    public void playVideo(String url) {
        if (videoView == null) return;
        play(url);
    }

    // 播放
    public native void play(String url);

    // 显示视频
    private native void display(Surface surface);

    // 释放资源
    public native void release();

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {

    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int i, int i1, int i2) {
        display(holder.getSurface());
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

    }
}
